<template>
  <div class="logs-manager-page">
    <el-form :inline="true" :model="searchObj" class="demo-form-inline">
      <el-form-item label="时间">
        <el-date-picker
            v-model="timer"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="操作者">
        <el-input v-model="searchObj.operName" placeholder="审批人"></el-input>
      </el-form-item>
      <el-form-item label="">
        <el-button type="primary" @click="queryMethods">查询</el-button>
        <el-button @click="clearLogMethods">清除日志</el-button>
      </el-form-item>
    </el-form>
    <CommonTable
      class="commonTable"
      ref="logsListRef"
      :is-selection="true"
      :is-show-index="true"
      :is-has-opera="false"
      :t-column-data="logsCol"
      :remote-api="getLogs"
      :query-params="searchObj"
      :is-reserve-select="true"
      @changeRow="changeRowMethods"
    >
      <template slot="log_content" slot-scope="scope">
        {{scope.row.title}}
      </template>
    </CommonTable>
  </div>
</template>

<script>
import moment from "moment";
import {logsCol} from './tableCol/logsCol'
import * as service from './service.js'
import {logsDeleteAll} from "./service.js";
export default {
  data() {
    return {
      logsCol,
      timer: [],
      getLogs: service.logsList,
      searchObj: {
        page: 1,
        pageSize: 20,
        operName: ''
      }
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    queryMethods() {
      this.searchObj.page = 1
      this.getList()
    },
    clearLogMethods() {
      this.$confirm('此操作将永久删除日志, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        service.logsDeleteAll().then(res => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
          this.getList()
        })
      })
    },
    getList() {
      const params = Object.assign({}, this.searchObj)
      if(this.timer && this.timer.length > 0) {
        params.begin = moment(this.timer[0]).format("YYYY-MM-DD")
        params.end = moment(this.timer[1]).format("YYYY-MM-DD")
      }
      this.$refs.logsListRef.queryData(params)
    },
    changeRowMethods() {

    }
  }
}
</script>

<style scoped lang="scss">
  .logs-manager-page{
    padding: 15px;
    background: white;
  }
</style>
